from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from items.uniform import Uniform
from core.support import set_cutscene
from core.support import get_game

class Closet(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # add inventory items
        
        # build list of actions
        self.add_action(CloseCloset)
        self.add_action(TakeUniform)
    
    # return description of room.
    def get_description(self):
        return "MacGyver is standing in a narrow closet and notices a guard's uniform."
    
    # return image of room
    def get_image(self):
        return 'closet.jpg'


class ClosetHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Closet

# define actions for this room

class TakeUniform(Action):
    def __init__(self):
        Action.__init__(self, "take_uniform")
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Steal Guard Uniform"
    
    def do_action(self,game,room,request):
        if get_game().get_player().has_item('uniform2'):
            set_cutscene("MacGyver doesn't need two uniforms.")
        elif get_game().get_player().can_pickup():
            set_cutscene("MacGyver puts on a guard uniform.")
            game.get_player().add_item(Uniform('uniform1'))
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        return not (player.has_item('uniform1') or game.get_room('closet', Closet).has_item('uniform1'))

class CloseCloset(Action):
    def __init__(self):
        Action.__init__(self, "CloseCloset")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Close Closet"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'wardensoffice'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
